<?php

	/// sqlhelper.php
	/// Copyright 		: Copyright (c) 2004
	///					: Thai Meteolorogical Department
	///					: This program is protected by copyright laws.
	///					: Unauthorized reproduction or distribution of this
	///					: program or any portion of it is Prohibited.
	/// Created By		: Yuttana Buasen
	/// Created Date	: 2004/10/14
	/// Change History	:
	/// DATE		BY				DESCRIPTION
	/// ------------------------------------------------------------------------------
	///

	include_once("adodb/adodb.inc.php");	
	
	class SqlHelper    
	{
		static public $MSSQL		= "MSSQL";
        static public $MYSQL		= "MySQL";
        static public $ORACLE		= "Oracle";
        static public $strDatabase 	= "MSSQL";
        
        public $strMsg = "";
                   	
        public static function OpenTransConn()
     	{
     		// Connection string for transactional database
         	
     		switch (SqlHelper::$strDatabase)
     		{
     			case SqlHelper::$MSSQL :
					$cn = &ADONewConnection("odbc_mssql");			
					$strTransConn = "Driver={SQL Server};Server=localhost;Database=TMDWEB_TEST;";		
					$cn->SetFetchMode(ADODB_FETCH_ASSOC);
					$cn->Connect($strTransConn,"sa","theangles");
					break;
					
				case SqlHelper::$MYSQL :
					$cn = &ADONewConnection("mysql");			
					$cn->SetFetchMode(ADODB_FETCH_ASSOC);
					$cn->Connect("Server","DBUsername","DBPassword","DBName");
					break;
     		}
		
			return $cn;
     	}
     	
     	public static function GetUpdateSQL($rs, $arr)
     	{
     		// Oracle has only DATE datatype which also includes both
     		//  date and time value
     		if ($rs->connection->dataProvider=="oci8")
     		{
     			$intFieldCount = $rs->FieldCount();
     		
	     		for ($i=0; $i<$intFieldCount; $i++)
				{
					$column[] = $rs->FetchField($i);
					if ($column[$i]->type=="DATE")
					{
						$column[$i]->type="TIMESTAMP";
					}
				}	     		
     		}
     		
     		$strSql = $rs->connection->GetUpdateSQL($rs, $arr);
     		
     		return $strSql;
     	}
     	
     }
?>